
<template>
  <div class="pwd">
    <div class="pwd-content">
      <div class="content-box1">
        <p class="title">忘记密码</p>
      </div>
      <div class="pwd-mav">
          <div class="nav-tab" :class="{'nav-tabActive': tabindex === 1}" ><span>1</span>找回密码</div>
          <div class="nav-tab" :class="{'nav-tabActive': tabindex === 2}" ><span>2</span>设置新密码</div>
      </div>
      <forget v-if="tabindex === 1"  @goNext="goNext" />
      <editPwd v-if="tabindex === 2"  @backUser="backUser"  @updatePwd="updatePwd"/>
    </div>
  </div>
</template>

<script>
import forget from './components/forget'
import editPwd from './components/editPwd'
import { changeUserPWD } from '@/api/system/user.js'
export default {
  components: {
    forget,
    editPwd
  },
  data () {
    return {
      tabindex: 1,
      params: {
        loginName: '',
        verCode: '',
        newPwd: ''
      }
    }
  },
  mounted () {},
  methods: {
    changeTab (index) {
      this.tabindex = index
    },
    backUser () {
      this.tabindex = 1
    },
    goNext (item) {
      this.params.loginName = item.loginName
      this.params.verCode = item.code
      this.tabindex = 2
    },
    updatePwd (item) {
      this.params.newPwd = item.password
      changeUserPWD(this.params).then((res) => {
        if (res.status === 200) {
          this.$Message.success('修改成功！请重新登录')
          this.$router.back(-1)
        } else {
          this.$Message.warning('请求失败，请联系管理员！')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import "./pwd.less";
</style>
<style  lang="less" scoped>

</style>
